var pargm;
$(function () {
    pargm = GetRequest();
    $.ajax({
        url: '/getDetailData',
        type: "GET",
        data: pargm,
        dataType: 'json',
        success: function (result) {
            if (result != null || 'undefined') {
                setInputValues(result);
            }
        },
        error: function () {
            console.error("请求失败")
        }
    });
})

function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

$('#save').click(function () {
    var rId = pargm.id;
    console.log(rId);
    registration = getInputValues(rId);
    console.log(registration);
    ajax.save(registration, function (result) {
        if (result.status == 0) {
            window.location.href = '/'
        }
    })
})

var registration = {
    id: 0,
    name: '',
    alias: '',
    imageUrl: '',
    gender: '',
    ethnic: '',
    birthday: '',
    height: '',
    idNumber: '',
    phone: '',
    physicalConditions: '',
    education: '',
    employer: '',
    residencePolice: '',
    residentPolice: '',
    residenceDetail: '',
    residentDetail: '',
    employmentStatus: '',
    drugTypes: '',
    seizedDate: '',
    seizedUnits: '',
    seizedPlace: '',
    natureCase: '',
    rehabilitationPeriod: '',
    checkInTime: '',
    drugAbuseTime: '',
    registerPerson: '',
    registerUnits: '',
    remarks: '',
    illegalFacts: '',
    drugRehabilitation: '',
    enclosureUrl: ''
}

function getInputValues(rId, urlObj) {
    registration.id = rId;
    registration.name = $("input[name='xing-ming']").val();
    registration.alias = $("input[name='bie-ming']").val();
    registration.gender = $("input[name='sex']").val();
    registration.imageUrl = $('#avatarImage').attr("src");
    registration.ethnic = $("input[name='min-zu']").val();
    registration.birthday = $("input[name='birthday']").val();
    registration.height = $("input[name='shen-gao']").val();
    registration.idNumber = $("input[name='id-number']").val();
    registration.phone = $("input[name='tel-phone']").val();
    registration.physicalConditions = $("input[name='shen-ti']").val();
    registration.education = $("input[name='culture-degree']").val();
    registration.employer = $("input[name='work-address']").val();
    registration.residencePolice = $("input[name='hjdpcs']").val();
    registration.residenceDetail = $("input[name='hjdxz']").val();
    registration.residentPolice = $("input[name='jzdpcs']").val();
    registration.residentDetail = $("input[name='jzdxz']").val();
    registration.employmentStatus = $("input[name='jyqk']").val();
    registration.drugTypes = $("input[name='drug-type']").val();
    registration.seizedDate = $("input[name='seizure-date']").val();
    registration.seizedUnits = $("input[name='seizure-unit']").val();
    registration.seizedPlace = $("input[name='location-seizure']").val();
    registration.natureCase = $("input[name='nature-case']").val();
    registration.illegalFacts = $("input[name='fact-malfeasance']").val();
    registration.drugRehabilitation = $("input[name='abandon-drug']").val();
    registration.rehabilitationPeriod = $("input[name='abandon-date']").val();
    registration.checkInTime = $("input[name='register-time']").val();
    registration.drugAbuseTime = $("input[name='drug-date']").val();
    registration.registerPerson = $("input[name='register-person']").val();
    registration.registerUnits = $("input[name='register-unit']").val();
    registration.remarks = $("input[name='remarks']").val();
    registration.enclosureUrl = $('#enclosure').attr('href');
    return registration;
}
